package work803.work2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class epService {
  public static List<Employee> employeeList = new ArrayList<>();
  static {
    employeeList.add(new Employee(1,"zhangsan",18,3000));
    employeeList.add(new Employee(2,"lisi",25,3500));
    employeeList.add(new Employee(3,"wangwu",22,3200));
  }

  /**
   * 增加新人
   * @param employee
   * @return
   */
  public static boolean addEmployee(Employee employee){
//    for (int i = 0; i <employeeList.size() ; i++) {
//              if (employee.getId() == employeeList.get(i).getId()){
//                throw new RuntimeException("工号重复");
//              }
//    }
    if (employeeList.contains(employee)){
      throw new RuntimeException("工号重复");
    }
    employeeList.add(employee);
    return true;
  }

  /**
   * 删除人员
   * @param name
   * @return
   */
  public static boolean delEmployee(String name){
    Iterator<Employee> employeeIterator = employeeList.iterator();
    while (employeeIterator.hasNext()){
      Employee employee = employeeIterator.next();
      if (employee.getName().equals(name)){
        employeeIterator.remove();
        return true;
      }
    }
    return false;
  }

  /**
   * 查看全部
   * @return
   */
  public static List<Employee> check(){
    List<Employee> list = new ArrayList<>();
    for (int i = 0; i <employeeList.size() ; i++) {
            if (employeeList.get(i) != null){
              list.add(employeeList.get(i));
            }
    }
    return list;
  }

  /**
   *工作
   * @return
   */
  public static List<String> work(){
  List<String> list = new ArrayList<>();
  for (int i = 0; i <employeeList.size() ; i++) {
    if (employeeList.get(i) != null){
      list.add(employeeList.get(i).getName()+"正在工作");
    }
  }
  return list;
}
}
